package com.qf.pickname.dao.impl;

import com.qf.pickname.dao.StudentDao;
import com.qf.pickname.entity.Student;
import com.qf.pickname.utils.StudentDataStore;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

// 添加该注解的作业和Service一样
@Repository
//@Component
public class SutdentDaoImpl implements StudentDao {
    @Override
    public Integer getStudentCount() {
        return StudentDataStore.students.size();
    }

    @Override
    public Student getStudentByIndex(Integer index) {
        return StudentDataStore.students.get(index);
    }

    @Override
    public Student getStudentByName(String name) {

        for (Student student : StudentDataStore.students) {
            if (name.equals(student.getName())){
                return student;
            }
        }

        return null;
    }

    @Override
    public void addStudent(String name, String sex) {

        Student student = new Student(StudentDataStore.idgenerator++, name, sex);
        StudentDataStore.students.add(student);

    }

    @Override
    public boolean hasNextStudent() {
        for (Student student : StudentDataStore.students) {
            if (student.getChecked().equals(0)){
                return true;
            }
        }
        return false;
    }

    @Override
    public List<Student> getUncheckedStudentList() {

        ArrayList<Student> students = new ArrayList<>();

        for (Student student : StudentDataStore.students) {
            if (student.getChecked()==0){
                students.add(student);
            }
        }

        return students;
    }
}
